package teeest;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import popcorn.ticket.entity.Orders;
import popcorn.ticket.entity.Schedule;
import popcorn.ticket.entity.Ticket;
import popcorn.ticket.service.OrdersService;
import popcorn.ticket.service.ScheduleService;
import popcorn.ticket.service.TicketService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class ZHIFULIUCHENG {
	
	@Autowired
	OrdersService os;
	
	@Autowired
	TicketService ts;
	
	@Autowired
	ScheduleService ss;
	
	@Test
	public void zhifu() {
		
		int orderid = 3711889;
		double price = 60;
		int scheduleid = 9;
		
		Orders order = os.getOrdersById(orderid);
		// 修改订单信息：支付成功 + 支付时间
		Date now = new Date();
		order.setPaytime(now);
		order.setOrderstatus(1);
		// 同时生成了影票信息
		os.updOrders(order);
		
		
		// 根据orderid 获取影票信息
		List<Ticket> list = ts.getTicketByOrderid(orderid);
		HashMap<String, Object> map1 = new HashMap<>();
		if(list.size()>1) {
			// 有两张票
			map1.put("ticketid1", list.get(0).getTicketid());
			map1.put("seat1", list.get(0).getSeat());
			map1.put("ticketid2", list.get(1).getTicketid());
			map1.put("seat2", list.get(1).getSeat());
			price = price / 2;
		}else {
			map1.put("ticketid1", list.get(0).getTicketid());
			map1.put("seat1", list.get(0).getSeat());
		}
		
		// 电影名 放映时间 影厅 根据排期获取
		Schedule schedule = ss.selScheduleByid(scheduleid);
		HashMap<String, Object> map2 = new HashMap<>();
		map2.put("moviename",schedule.getMovies().getMoviename());
		map2.put("playtime", schedule.getPlaytime());
		map2.put("hallname", schedule.getHall().getHallname());
	}
	
}
